<html>
<head><meta charset="utf-8"><title>target-cpu=native for host · t-cargo · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/index.html">t-cargo</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html">target-cpu=native for host</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221055492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221055492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221055492">(Dec 28 2020 at 11:43)</a>:</h4>
<p>I would like to globally set <code>-C target-cpu=native</code> for builds on my machine, but that spams output when doing a cross-compile</p>
<div class="codehilite"><pre><span></span><code>&#39;znver2&#39; is not a recognized processor for this target (ignoring processor)
</code></pre></div>
<p>is there some way to set this under something like <code>[target.host]</code> to only set it when building for the host target?</p>



<a name="221058982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221058982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221058982">(Dec 28 2020 at 13:01)</a>:</h4>
<p>You can set per-target rustflags: <a href="https://doc.rust-lang.org/cargo/reference/config.html#targettriplerustflags">https://doc.rust-lang.org/cargo/reference/config.html#targettriplerustflags</a></p>



<a name="221059029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221059029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221059029">(Dec 28 2020 at 13:02)</a>:</h4>
<p>either in the config file itself or via the environment variable overrides</p>



<a name="221059037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221059037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221059037">(Dec 28 2020 at 13:02)</a>:</h4>
<p><code>CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS</code> in this case</p>



<a name="221072049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221072049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221072049">(Dec 28 2020 at 16:25)</a>:</h4>
<p>yeah, but I share my config between different hosts</p>



<a name="221073973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221073973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221073973">(Dec 28 2020 at 16:54)</a>:</h4>
<p><span class="user-mention" data-user-id="210267">@Nemo157</span> But you don't share binaries between hosts?</p>



<a name="221074003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221074003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221074003">(Dec 28 2020 at 16:55)</a>:</h4>
<p>Do you just want this for <code>cargo install</code>, or for other kinds of builds too?</p>



<a name="221074014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221074014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221074014">(Dec 28 2020 at 16:55)</a>:</h4>
<p>no, I share my <code>~/.cargo/config</code> between hosts, so if I set <code>-C target-cpu=native</code> on specific targets that would apply during cross-compilation on some hosts</p>



<a name="221074017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221074017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221074017">(Dec 28 2020 at 16:55)</a>:</h4>
<p>all builds</p>



<a name="221074117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221074117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221074117">(Dec 28 2020 at 16:56)</a>:</h4>
<p>Do you ever cross-compile to x86_64 from a non-x86_64 host?</p>



<a name="221074153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221074153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221074153">(Dec 28 2020 at 16:57)</a>:</h4>
<p>I might occasionally cross compile to x86_64-unknown-linux-gnu from x86_64-apple-darwin</p>



<a name="221074220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221074220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221074220">(Dec 28 2020 at 16:58)</a>:</h4>
<p>Then in that case, I would suggest that you add some code to your .bashrc to determine what host type you're on and set the target-specific RUSTFLAGS accordingly.</p>



<a name="221074266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221074266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221074266">(Dec 28 2020 at 16:59)</a>:</h4>
<p>yeah, I can go the route of building custom <code>~/.cargo/config</code></p>



<a name="221074270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221074270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221074270">(Dec 28 2020 at 16:59)</a>:</h4>
<p>I was just hoping not to</p>



<a name="221074278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221074278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221074278">(Dec 28 2020 at 16:59)</a>:</h4>
<p>You don't have to build a custom file.</p>



<a name="221074290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221074290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221074290">(Dec 28 2020 at 16:59)</a>:</h4>
<p>Just check uname and set environment variables.</p>



<a name="221074378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221074378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221074378">(Dec 28 2020 at 17:00)</a>:</h4>
<p>eh, I prefer being able to see all the config in a file, and my dotfile management can import parts based on uname</p>



<a name="221074421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221074421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221074421">(Dec 28 2020 at 17:01)</a>:</h4>
<p>One other option then: pick the x86_64 baseline that's common to your systems and optimize for that, which will give you the vast majority of the optimization benefit.</p>



<a name="221074506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221074506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221074506">(Dec 28 2020 at 17:02)</a>:</h4>
<p>Unless you have some fairly old systems, or some high-end recent server systems, you can likely pick a baseline of "everything except AVX512" and get good benefits.</p>



<a name="221074568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/target-cpu%3Dnative%20for%20host/near/221074568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/target-cpu.3Dnative.20for.20host.html#221074568">(Dec 28 2020 at 17:04)</a>:</h4>
<p>(Newer LLVM will let you just spell that "x86_64-v3".)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>